package hui.zhang.web.action.transit;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;

import hui.zhang.domain.transit.TransitInfo;
import hui.zhang.service.transit.TransitInfoService;
import hui.zhang.utils.BaseAction;

/**
 * 配送管理
 * @author hui.zhang
 * @date 2018年1月3日 下午6:59:11
 */

@ParentPackage("struts-default")
@Namespace("/")
@Controller
@Scope("prototype")
@SuppressWarnings("all")
public class TransitInfoAction extends BaseAction<TransitInfo> {

	@Autowired
	private TransitInfoService transitInfoService;
	
	private String wayBillIds;
	public void setWayBillIds(String wayBillIds) {
		this.wayBillIds = wayBillIds;
	}
	
	// 开始配送
	@Action(value="transit_create")
	public String create() {
		// 保存transitInfo信息
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			transitInfoService.createTransits(wayBillIds);
			map.put("success", true);
			map.put("msg", "开启中转配送成功！");
		} catch (Exception e) {
			e.printStackTrace();
			map.put("success", false);
			map.put("msg", "开启中转配送失败！");
		}
		toJsonAndResponse(map);
		return NONE;
	}
	
	@Action(value="transit_pageQuery")
	public String pageQuery() {
		Pageable pageable = new PageRequest(page - 1, rows);
		Page<TransitInfo> pageData = transitInfoService.findByPage(pageable);
		toJsonAndResponse(pageData);
		return NONE;
	}
}
